package com.epoint.action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epoint.common.Result;
import com.epoint.entity.BookInfo;
import com.epoint.service.BookInfoService;

/**
 * Servlet implementation class BookInfoAddAction
 */
@WebServlet("/bookinfoaddaction")
public class BookInfoAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	BookInfoService bookInfoService = new BookInfoService();
    public BookInfoAddAction() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String data = request.getParameter("data");
		
		// 将json字符串转为BookInfo对象
		JSONObject jsonObject = JSONObject.parseObject(data);
		BookInfo bookInfo = JSON.toJavaObject(jsonObject,BookInfo.class);

		int flag = bookInfoService.addBookInfo(bookInfo);

		String returnCode = Result.returnCode(flag);
		response.getWriter().print(returnCode);
	}

}
